package com.openlogic.common.logic.utils;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * @ClassName: NumericRegxUtils
 * @Description: 数字正则匹配工具类
 * @author weiyongpeng
 * @date 2024年7月14日 上午11:40:32
 */
public class NumericRegxUtils {

	public static boolean isNumeric(String str) {
		return (isRegularMatch("[+-]{0,1}0", str)) || (isPosInteger(str)) || (isNegInteger(str));
	}

	public static boolean isPosInteger(String str) {
		return isRegularMatch("^\\+{0,1}[1-9]\\d*", str);
	}

	public static boolean isNegInteger(String str) {
		return isRegularMatch("^-[1-9]\\d*", str);
	}

	public static boolean isDecimal(String str) {
		return isRegularMatch("[-+]{0,1}\\d+\\.\\d*|[-+]{0,1}\\d*\\.\\d+", str);
	}

	private static boolean isRegularMatch(String regex, String orginal) {
		if ((orginal == null) || (orginal.trim().equals(""))) {
			return false;
		}
		Pattern pattern = Pattern.compile(regex);
		Matcher isNum = pattern.matcher(orginal);
		return isNum.matches();
	}

	public static boolean isNumber(String str) {
		return isRegularMatch("^(\\-|\\+)?\\d+(\\.\\d+)?$", str);
	}

}
